public class ClassA {
    
    private String marketNews = null;
    
    public void setData (String news){
        marketNews = news;
    }

    /**
     * @param args
     */
    public static void main(String[] args) {
        ClassA aInstance = new ClassA();
        aInstance.someMethod();
    }
    
    void someMethod(){
        ClassB myB = new ClassB(this);
        myB.start();
        for(int i=0; i<100; i++){
        synchronized(this){
        try{
            wait();
        }
        catch(InterruptedException e){
            e.printStackTrace();
        }
        }        
        System.out.println("Market news: "+marketNews);
        System.out.println(i);
        }
    }
}

class ClassB extends Thread{
    
    private ClassA parent = null;
    
    ClassB(ClassA caller){
        parent = caller;
    }
    
    public void run(){        
            for(int i=0; i<1000; i++){
                //parent.setData("Economy is recovering...");
                //System.out.println("You have "+ (500+i) +" shares of IBM");
                parent.setData("You have "+ (500+i) +" shares of IBM");
                synchronized(parent){
                    parent.notify();
                }
            }
    }
}

